09. Exercise: Add the VideoDao
L9 13 VideoDao SC
Now it’s your turn to complete this exercise yourself.
For this task you need to implement VideoDao in database/Room.kt.
1. In database/Room.kt, define a @Dao interface called VideoDao:
@Dao
interface VideoDao { }
2. Add getVideos() Query function to VideoDao that returns a List of DatabaseVideo:
@Query("select * from databasevideo")
fun getVideos(): List<DatabaseVideo>
3. Add an Insert function called insertAll() to your VideoDao that takes vararg DatabaseVideo:
insertAll() is an upsert, so don’t forget to pass it onConflict=OnConflictStrategy.REPLACE!
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(vararg videos: DatabaseVideo)
If you want to start at this step, you can download this exercise code from: Step.02-Exercise-Add-VideoDao.
You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck go back and watch the video again.
Once you’re done, you can check your solution against the solution we’ve provided here Step.02-Solution-Add-VideoDao or using this git diff
Task Feedback:
Great work! That’s all for now. Next up we have a refactoring task for you to do!